<template>
  <div class="freeClass">
    <Appheader :parentToChild="ymname" @refresh="refresh"></Appheader>
    <!-- <div v-html="long_img" class="longimg"></div> -->
    <div class="content" v-loading="loading">
      <div class="class">
        <!-- <div class="class_one flex">
          <img src="../../assets/free_book.png" alt />
          免费试听
        </div> -->
        <ul class="b_bottom">
          <li v-for="(list,index) in listarry" :key="index">
            <img :src="list.photo" alt @click="xkdetail(list.id)" />
            <div class="b_bottom_a flex" @click="xkdetail(list.id)">
              <p class="hidden">{{list.title}}</p>
              <p v-if="list.ykAuthor">{{list.ykAuthor.authorName}}</p>
            </div>
          </li>
        </ul>
        <div class="page" v-if="total!=0">
          <div class="page_a" @click="handleCurrentChange(1)">首页</div>
          <el-pagination
            background
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage"
            layout="prev, pager, next"
            :total="total"
            :page-size="9"
          ></el-pagination>
          <div class="page_a" @click="handleCurrentChange('w')">尾页</div>
        </div>
        <div v-else class="tip2">
          <img src="../../assets/none.png" alt />
        </div>
      </div>
    </div>
    <Appfooter></Appfooter>
  </div>
</template>

<script>
import { Professionallist, ykGoodslist, channelTime } from "../../api/index";
import Appheader from "./headers";
import Appfooter from "../footer";
import $ from "jquery";
export default {
  props: {},
  data() {
    return {
      ymname: "免费试听",
      loading: true,
      zhuanyef: [],
      xuankeA: {
        id: "",
        name: "全部"
      },
      choose_classify: "全部",
      choose_id: "",
      currentPage: 1,
      total: 0, //列表总数
      pagenum: 1, //请求的页数
      pagesize: 9, //请求的数量
      listarry: [], //请求的数据
      timers: "",
      long_img: ""
    };
  },
  computed: {},
  created() {
    sessionStorage.setItem("nowPage", "freePd");
  },
  mounted() {
    this.type = this.$route.params.type;
    this.choose_id = this.$route.params.pId;
    console.log(this.choose_id)
    let msg2 = {
      title: "免费试听"
    };
    channelTime(this.qs(msg2))
      .then(res => {
        // console.log(res)
        this.long_img = res.data.ykPc.content;
      })
      .catch(e => {});
    Professionallist()
      .then(res => {
        if (res.data.code == 0) {
          res.data.rows.unshift(this.xuankeA);
          this.zhuanyef = res.data.rows;
        }
      })
      .catch(e => {});
    this.post();
  },
  watch: {},
  methods: {
    refresh(res) {
      // console.log("触发");
      this.type = res.type;
      this.choose_id = res.id;
      localStorage.setItem("profationId", this.choose_id);
      localStorage.setItem("type", this.type);
      this.post();
    },
    post() {
      let msg = {
        type: "2",
        pId: this.choose_id,
        pageNum: this.pagenum,
        pageSize: this.pagesize,
        free: 1
      };
      ykGoodslist(this.qs(msg))
        .then(res => {
          if (res.data.code == 0) {
            this.listarry = res.data.rows;
            this.total = res.data.total;
          }
          this.loading = false;
        })
        .catch(e => {});
    },
    listf(id) {
      this.choose_id = id;
      this.pagenum = 1;
      this.currentPage = 1;
      this.post();
    },
    handleCurrentChange(val) {
      if (val == "w") {
        this.pagenum = Math.ceil(this.total / this.pagesize);
      } else {
        this.pagenum = val;
      }
      this.currentPage = this.pagenum;
      this.loading = true;
      this.post();
    },
    //视频
    xkdetail(id) {
      this.$router.push({
        name: "keList",
        params: {
          id: id
        }
      });
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    }
  },
  components: { Appheader, Appfooter }
};
</script>

<style scoped>
.longimg {
  width: 100%;
  height: 350px;
}
.content {
  width: 1200px;
  margin: 0 auto;
}
.freeClass {
  /* background: #f5f8f7; */
}
/*  */
.class {
  width: 100%;
  background: #363640;
  padding-top: 30px;
  padding-bottom: 50px;
}
.class_one,
.free_mingshi > .class_one {
  font-size: 24px;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  margin-bottom: 30px;
}
.class_one > img,
.free_mingshi > img {
  width: 25px;
  height: 24px;
  margin-left: 14px;
  margin-right: 9px;
}
.free_other {
  font-size: 14px !important;
  font-weight: normal !important;
  cursor: pointer;
}
.free_other > img {
  width: 7px;
  height: 13px;
  margin-left: 10px;
  margin-right: 24px;
}
.b_bottom {
  padding: 0 33px;
}
.b_bottom li {
  width: 344px;
  margin-bottom: 42px;
  margin-right: 51px;
  box-sizing: border-box;
  cursor: pointer;
}
.b_bottom li:nth-child(3n) {
  margin-right: 0px;
}
.b_bottom li > img {
  width: 100%;
  height: 200px;
  border-radius: 20px;
}
.b_bottom_a {
  font-size: 16px;
  color: #c0c1c5;
  margin-top: 5px;
  justify-content: space-between;
  flex-direction: column;
}
.b_bottom_a > p:nth-child(1) {
  width: 255px;
}
.b_bottom_a > p{
  line-height: 30px;
}
.b_bottom {
  display: flex;
  flex-wrap: wrap;
}
/* page */
.page {
  display: flex;
  justify-content: center;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.page >>> .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #c8a94f !important;
}
.page >>> .el-pager li,
.page >>> .btn-next,
.page >>> .btn-prev {
  width: 34px;
  height: 34px;
  padding: 0;
  line-height: 34px;
  text-align: center;
  border-radius: 5px;
}
.page_a {
  width: 34px;
  height: 34px;
  background: rgba(243, 243, 243, 1);
  border-radius: 5px;
  font-size: 12px;
  color: #333;
  line-height: 34px;
  text-align: center;
}
.page_a:hover {
  background: #c8a94f;
  color: #fff;
}
</style>
